package org.i1510.common.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Service;

import com.ibatis.sqlmap.client.SqlMapClient;



/*
 * 基本框架 所有的spring dao impl类都继承该类
 * */

public class BaseServiceImpl {



	/**
	 * 以私有成员变量保存SqlMapClient
	 */
	@Autowired
	private SqlMapClient sqlMapClient;//需要有set方法注入


	

	/**
	 * 以私有成员变量保存iBatis模板SqlMapClientTemplate
	 */
	
	private SqlMapClientTemplate sqlMapClientTemplate;
	/**
	 * 获取iBatis模板对象
	 * 
	 * @return SqlMapClientTemplate iBatis模板对象
	 */
	public SqlMapClientTemplate getSqlMapClientTemplate() {
		//首先检查原来的SqlMapClientTemplate实例是否存在
		if (this.sqlMapClientTemplate == null) {
			//如果不存在，则创建一个SqlMapClientTemplate实例
			this.sqlMapClientTemplate = new SqlMapClientTemplate(
					this.sqlMapClient);
		}
		return this.sqlMapClientTemplate;
	}
	
	
	public Object insertBySql(String statementId, Object value) {
		return this.getSqlMapClientTemplate().insert(statementId, value);
	}

	public int deleteBySql(String statementId, Object value) {
		return this.getSqlMapClientTemplate().delete(statementId, value);
	}

	
	public int updateBySql(String statementId, Object value) {
		return this.getSqlMapClientTemplate().update(statementId, value);
	}

	public List queryForListBySql(String statementId, Object value) {
		List list = this.getSqlMapClientTemplate().queryForList(statementId,
				value);
		return list;
	}




}
